package com.zb.Service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zb.Service.FiletableService;
import com.zb.entity.Filetable;
import com.zb.entity.Tree;
import com.zb.mapper.FiletableMapper;



@Component
public class FiletableServiceImpl implements FiletableService{
	
	@Autowired
	private FiletableMapper ftm;
	
	public Filetable getFileById(int id) {
		return ftm.getFileById(id);
	}
	
	public List<Tree> showRootFile(int did) {
		List<Filetable>ftlist =  ftm.getRootFile(did);
		List<Tree> tlist = new ArrayList<Tree>();
		for (Filetable ft : ftlist) {
			Tree t = new Tree();
			t.setId(ft.getId());
			t.setText(ft.getName());
			t.setIconCls("icon-folder");
			tlist.add(t);
		}
		return tlist;
	}

	public List<Filetable> getListById(int pid, int uid) {
		Map<String, Object> map =  new HashMap<String, Object>();
		map.put("pid", pid);
		map.put("uid", uid);
		List<Filetable> flist = ftm.getListById(map);
		return flist;
	}
	
	public List<Filetable> getListByPid(int did){
		List<Filetable> flist = ftm.getListByPid(did);
		return flist;
	}

	public Filetable getRootFileByDeptId(int did) {
		Filetable ft = ftm.getRootFileByDeptId(did).get(0);
		return ft;
	}

	public int updateFileInfo(Filetable ft) {
		return ftm.updateFileInfo(ft);
	}

	public List<Filetable> getChildByPath(String path) {
		return ftm.getChildByPath(path);
	}

	public int addFile(Filetable ft) {
		return ftm.addFile(ft);
	}

	public int updateFileState(Filetable ft) {
		return ftm.updateFileState(ft);
	}

	public List<Filetable> getDeleteFileList(int userid) {
		return ftm.getDeleteFileList(userid);
	}

	public int delectFileById(int id) {
		return ftm.delectFileById(id);
	}

	public int delectFlistByPath(String path) {
		return ftm.delectFlistByPath(path);
	}

	public int delectFlieByDeptId(int did) {
		return ftm.delectFlieByDeptId(did);
	}


	
}